#!/bin/bash
if [ ! -d /sys/bus/i2c/devices/i2c-1/1-0004 ]
then
	echo "there has no gpio driver"
	exit 
fi

gpioset 4 5=1
gpioset 7 11=1
gpioset 7 16=1

power_on() 
{
	echo "power on"
	gpioset 4 5=0
	sleep 0.3
	gpioset 4 5=1
}

power_off()
{
	echo "power off"
	gpioset 4 5=0
	sleep 1.5
	gpioset 4 5=1
}

soft_power_off()
{
	echo "power soft off"
	gpioset 7 16=0
	sleep 0.3
	gpioset 7 16=1
}

power_reset()
{
	echo "power reset"
	gpioset 7 11=0
	sleep 1.5
	gpioset 7 11=1
}
soft_power_reset()
{
	echo "power soft reset"
	gpioset 7 11=0
	sleep 0.3
	gpioset 7 11=1
}
case "$1" in
on)
    power_on
    ;;
off)
    power_off
    ;;
soff)
	soft_power_off
    ;;
reset)
    power_reset
    ;;
sreset)
	soft_power_reset
	;;   
*)
    echo "invalid cmd $1" >&2
    exit 1
    ;;
esac
